package com.gitee.feizns.convert.method;

import com.gitee.feizns.convert.Converter;

import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author feizns
 * @since 2019/5/28
 */
public abstract class AbstractMethodConverter implements MethodConverter {

    /**
     * 帮助方法装换的，其他转换器列表
     */
    protected TreeSet<Converter> converters;

    @Override
    public void setConverters(TreeSet<Converter> converters) {
        this.converters = converters;
    }

    @Override
    public boolean support(Class targetType) {
        return true;
    }

    @Override
    public int priority() {
        return Integer.MAX_VALUE;
    }

    /**
     * 获取支持的转换器
     * @param targetType
     * @return
     */
    public List<Converter> getSupportConverter(Class<?> targetType) {
        return converters.stream()
                .filter(converter -> converter.support(targetType))
                .collect(Collectors.toList());
    }

}
